package cn.rxls.admin.shop.service.impl;

import cn.rxls.admin.shop.dto.PageShopDTO;
import cn.rxls.admin.shop.entity.Shop;
import cn.rxls.admin.shop.mapper.ShopMapper;
import cn.rxls.admin.shop.service.ShopService;
import cn.rxls.admin.shop.vo.PageShopVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商品(Shop)表服务实现类
 *
 * @author makejava
 * @since 2024-05-10 02:17:07
 */
@Service("shopService")
@Transactional
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {

    private final ShopMapper shopMapper;

    ShopServiceImpl(ShopMapper shopMapper){
        this.shopMapper = shopMapper;
    }

    /**
     * 分页查询
     *
     * @param dto 参数对象
     * @return 多条数据
     */
    @Override
    public PageShopVO page(PageShopDTO dto) {
        //计算页码
        dto.setPage((dto.getPage()-1)*dto.getSize());
        Integer count = shopMapper.count(dto);
        List<Shop> page = shopMapper.page(dto);
        PageShopVO pageShopVO = new PageShopVO();
        pageShopVO.setShop(page);
        pageShopVO.setTotal(count);
        return pageShopVO;
    }

    /**
     * 统计数据
     *
     * @param dto 参数对象
     * @return 数据条数
     */
    @Override
    public Integer count(PageShopDTO dto) {
        return shopMapper.count(dto);
    }
}

